import moment from "moment"
//文件大小单位换算
function formatFileSize (fileSize) {
  if(!fileSize) return ''
  fileSize=fileSize+''
  fileSize = fileSize.replace(/,/g, "")
  fileSize =Number(fileSize.replace(/\s/g, ""))
  if(fileSize < 0){
    return 0
  }else if (fileSize < 1024) {
    return fileSize + ' B'
  } else if (fileSize < 1024 * 1024) {
    var temp = fileSize / 1024
    temp = temp.toFixed(2)
    return temp + ' KB'
  } else if (fileSize < 1024 * 1024 * 1024) {
    var temp = fileSize / (1024 * 1024)
    temp = temp.toFixed(2)
    return temp + ' MB'
  } else {
    var temp = fileSize / (1024 * 1024 * 1024)
    temp = temp.toFixed(2)
    return temp + ' GB'
  }
}
const install = (Vue) => {

	Vue.filter('formatDate',(v,format='YYYY-MM-DD HH:mm:ss')=> {
    if(!v) return ''
    return moment(v).format(format)
  })

  Vue.filter('formatFileSize', formatFileSize)
  
}

export default {
	install
}